package top.lishuoboy.druid.sb.controller;

import cn.hutool.core.util.RandomUtil;
import cn.hutool.db.DbUtil;
import cn.hutool.db.Entity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.List;

/**
 * @author lishuoboy
 * @date 2022/4/21 16:02
 */
@RestController
public class DruidController {
    @Autowired
    private DataSource dataSource;

    @GetMapping("hello")
    private Object hello() {
        return dataSource.getClass();
    }

    @GetMapping("runSql")
    private Object runSql() throws SQLException {
        List<Entity> entityList = DbUtil.use(dataSource).query("select * from user where id = ?", RandomUtil.randomInt(3));
        return entityList;
    }
}
